# -*- coding: utf-8 -*-

"""
Created on Fri Jun  8 18:43:24 2018

@author: Administrator
"""
from multiprocessing import cpu_count
from multiprocessing.dummy import Pool as ThreadPool
#from pathos.multiprocessing import ProcessingPool as Pool
print('parallel--parallel--parallel')

#%%
class PoolMap(object):
    
    #作用原理：
    #参数说明：
    #参数说明：processing_parameter_list,core_percent
    #返回值说明：
    #举例：
    #父类：
    #子类：AgilePipe
    #调用：
    #被调用:
    #bug：

    def __init__(self,function,processing_parameter_list,core_percent):

        parallel_core = int(cpu_count() * abs(core_percent))
        if parallel_core == 0:
            #至少用1个核心来运算，防止百分比太小，导致parallel_core，使运算无法进行。
            parallel_core = 1
        if parallel_core >= cpu_count():
            #至多用cpu_count()-1个核心来运算，防止机器卡死。
            parallel_core = parallel_core - 1
        pool = ThreadPool(parallel_core)
        self.process_result_list = pool.map(function,processing_parameter_list)
        pool.close()
        pool.join()